<template>
  <div>
    <nav-bar :title="title"></nav-bar>
    <div class="maxinBox">
      <div class="backgroundfff">
        <van-row class="realTimeTask" @click="listDetails(item)" v-for="(item, index) in towerList" :key="index">
          <van-col :span="7">
            <img style="width: 90%;" :src="item.driverHeadUrl" alt="" @click="bigImg(item.driverHeadUrl)">
          </van-col>
          <van-col :span="17">
            <div style="padding: 0.3125rem 0;">
              <span class="fontSize16">{{item.deviceName}}</span>
              <van-button size="mini" plain type="primary" v-if="item.onlineText === '在线'">
                <span>在线</span>
              </van-button>
              <van-button size="mini" plain type="danger" v-else>
                <span>离线</span>
              </van-button>
            </div>
            <div style="color: #666;" class="fontSize14" v-if="item.driverName">司机姓名: {{item.driverName || '--'}}</div>
            <div style="color: #666;" class="fontSize14" v-else>司机姓名: --</div>
            <div style="color: #666;" class="fontSize14" v-if="item.driverMobile">联系方式: {{item.driverMobile || '--'}}</div>
            <div style="color: #666;" class="fontSize14" v-else>联系方式: --</div>
            <van-radio-group style="color: #666;" class="fontSize14" v-model="item.alarmText" direction="horizontal" disabled>
              工作状态: &nbsp;&nbsp;&nbsp;&nbsp;
              <van-radio name="正常">正常</van-radio>
              <van-radio name="告警">告警</van-radio>
            </van-radio-group>
          </van-col>
        </van-row>
      </div>
    </div>

  </div>
</template>

<script>
  import {ImagePreview} from 'vant'
  import hardwareManageAPI from '../../../../api/workAPI/hardwareManageAPI.js'
  export default {
    data() {
      return {
        towerList: [],
        title: localStorage.getItem('hardwareType')
      }
    },
    methods: {
      // 放大图片
      bigImg(img) {
        ImagePreview({
           images: [img],
        })
      },
      getTowerList() {
        let projectId = localStorage.getItem('projectId')
        hardwareManageAPI.getTowerList(projectId).then(res => {
          res.list[0].towerList.map(item => {
            this.towerList.push({
              id: item.id,
              deviceName: item.deviceName,
              onlineText: item.onlineText,
              driverName: item.driver.driverName,
              driverMobile: item.driver.driverMobile,
              alarmText: item.alarmText,
              driverHeadUrl: item.driver.driverHeadUrl
            })
          })
        })
      },
      getLifterList() {
        hardwareManageAPI.getLifterList().then(res => {
          res.list.map(item => {
            this.towerList.push({
              id: item.deviceId,
              deviceName: item.deviceName,
              onlineText: item.online,
              driverName: item.driveName,
              driverMobile: item.phone,
              alarmText: item.workStatus,
              driverHeadUrl: item.url
            })
          })
        })
      },
      listDetails(data) {
        localStorage.setItem('hardwareData', JSON.stringify(data))
        if (this.title === '升降机列表') {
          this.$router.push({
            name: 'LifterDetails'
          })
        } else {
          this.$router.push({
            name: 'HardwareListDetails'
          })
        }

      }
    },
    mounted() {
      if (localStorage.getItem('hardwareType') === '升降机列表') {
        this.getLifterList()
      } else {
        this.getTowerList()
      }
    }
  }
</script>
<style scoped lang="scss">
.realTimeTask{
    padding: 0.9375rem;
    font-size: 0.875rem;
    border-bottom: 0.0625rem solid #E5E5E5;
    .van-col--7{
      img{
        width: 100%;
        display: inline-block;
        vertical-align: middle;
      }
    }
  }
</style>
